/**
 * 省市区公司多选选择下拉tree
 */
function initCompMultiTree() {
    var setting = {
        async: {
            enable: true,
            url:"/company/getCompSelect",
            autoParam:["id", "name=n", "level=lv"],
            dataFilter: compFilter
        },
        callback: {
            beforeClick: beforeCompClick,
            onCheck: onCheck
        },
        view: {
            showLine:false,
            dblClickExpand: false
        },
        check: {
            enable: true,
            chkboxType: {"Y":"", "N":""}
        },

    };
    $.fn.zTree.init($("#treeComp"), setting);
}

function compFilter(treeId, parentNode, childNodes) {
    if (!childNodes) return null;
    for (var i=0, l=childNodes.length; i<l; i++) {
        childNodes[i].name = childNodes[i].name.replace(/\.n/g, '.');
    }
    return childNodes;
}

function beforeCompClick(treeId, treeNode) {
    var zTree = $.fn.zTree.getZTreeObj("treeComp");
    zTree.checkNode(treeNode, !treeNode.checked, null, true);
    return false;
}

function onCheck(e, treeId, treeNode) {
    var zTree = $.fn.zTree.getZTreeObj("treeComp"),
        nodes = zTree.getCheckedNodes(true),
        v = "",
        ids = "";
    for (var i=0, l=nodes.length; i<l; i++) {
        v += nodes[i].name + ",";
        ids += nodes[i].id + ",";
    }
    if (v.length > 0 ) {
        v = v.substring(0, v.length-1);
    }
    $("#compSelect").val(v);

    if (ids.length > 0 ) {
        ids = ids.substring(0, ids.length-1);
    }
    $("#compSelectIds").val(ids);
}

function showCompSelect() {
    initCompMultiTree();
    var cityObj = $("#compSelect");
    var cityOffset = $("#compSelect").offset();
    $("#compContent").css({left:cityOffset.left + "px", top:cityOffset.top + cityObj.outerHeight() + "px"}).slideDown("fast");
    $("body").bind("mousedown", onComBodyDown);
}
function hideCompMenu() {
    $("#compContent").fadeOut("fast");
    $("body").unbind("mousedown", onComBodyDown);
}
function onComBodyDown(event) {
    if (!(event.target.id == "compBtn" || event.target.id == "compContent"
        || $(event.target).parents("#compContent").length>0)) {
        hideCompMenu();
    }
}

/*
function onClick(e, treeId, treeNode) {
    var zTree = $.fn.zTree.getZTreeObj("treeComp");
    var nodes = zTree.getSelectedNodes();

    var countyName = "";
    var cityName = "";
    var provinceName = "";
    if(nodes != null && nodes.length > 0){
        //set countyId
        countyName = nodes[0].name;
        var selectId = nodes[0].id;
        $("#countyId").val(selectId);

        var cityNodes = nodes[0].getParentNode();
        if(cityNodes != undefined) {
            cityName = cityNodes.name;
        }
        var proNodes = cityNodes.getParentNode();
        if(proNodes != undefined){
            provinceName = proNodes.name;
        }
    }
    var value = provinceName + cityName + countyName;
    $("#county").val(value);
}*/

//点击选择，显示下拉树
/*function showAreaSelect() {
    initAreaTree();
    var cityObj = $("#county");
    var cityOffset = $("#county").offset();
    $("#menuContent").css({left:cityOffset.left + "px", top:cityOffset.top + cityObj.outerHeight() + "px"}).slideDown("fast");
    $("body").bind("mousedown", onBodyDown);
}
function hideMenu() {
    $("#menuContent").fadeOut("fast");
    $("body").unbind("mousedown", onBodyDown);
}
function onBodyDown(event) {
    if (!(event.target.id == "menuBtn" || event.target.id == "menuContent"
        || $(event.target).parents("#menuContent").length>0)) {
        hideMenu();
    }
}*/





